﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AuctionHelper.Core;
using AuctionHelper.Entity;

namespace AuctionHelper.Business
{
    /// <summary>
    /// 元素业务类
    /// </summary>
    internal class ElementBLL
    {
        /// <summary>
        /// 设置列表项
        /// </summary>
        /// <param name="listItem"></param>
        internal static void SetListItem(ListItem listItem)
        {
            if (listItem != null)
            {
                InputHelper.MouseMove(listItem.Position.Click_X, listItem.Position.Click_Y);
                InputHelper.MouseClick();
                InputHelper.MouseMove(listItem.ItemInListPosition.Click_X, listItem.ItemInListPosition.Click_Y);
                InputHelper.MouseClick();
                InputHelper.MouseMove(0, 0);
            }
        }

        /// <summary>
        /// 设置带滚动条的列表项
        /// </summary>
        /// <param name="scrollListItem"></param>
        internal static void SetScrollListItem(ScrollListItem scrollListItem)
        {
            if (scrollListItem != null)
            {
                InputHelper.MouseMove(scrollListItem.Position.Click_X, scrollListItem.Position.Click_Y);
                InputHelper.MouseClick();
                InputHelper.MouseMove(scrollListItem.ListPosition.Click_X, scrollListItem.ListPosition.Click_Y);
                InputHelper.MouseWheel(scrollListItem.WheelUpToTopHeight);
                InputHelper.MouseWheel(-scrollListItem.WheelDownToItemHeight);
                InputHelper.MouseMove(scrollListItem.ItemInListPosition.Click_X, scrollListItem.ItemInListPosition.Click_Y);
                InputHelper.MouseClick();
                InputHelper.MouseMove(0, 0);
            }
        }

        /// <summary>
        /// 设置文本项
        /// </summary>
        /// <param name="text"></param>
        internal static void SetText(Text text)
        {
            if (text != null)
            {
                InputHelper.MouseMove(text.Position.Click_X, text.Position.Click_Y);
                InputHelper.MouseDoubleClick();
                InputHelper.SendKey(text.Value.ToString());
                InputHelper.MouseMove(0, 0);
            }
        }

        /// <summary>
        /// 按钮点击
        /// </summary>
        /// <param name="button"></param>
        internal static void ButtonClick(Button button)
        {
            if (button != null)
            {
                var sourceSignature = ImageBLL.GetImageSignature(button.SignaturePosition);
                InputHelper.MouseMove(button.Position.Click_X, button.Position.Click_Y);
                InputHelper.MouseClick();
                InputHelper.MouseMove(0, 0);
                var targetSignature = ImageBLL.GetImageSignature(button.SignaturePosition);
                while (!ImageBLL.CompareImageSignature(sourceSignature, targetSignature))
                {
                    targetSignature = ImageBLL.GetImageSignature(button.SignaturePosition);
                }
            }
        }
    }
}
